/*
 * @Author: your name
 * @Date: 2021-11-09 19:07:13
 * @LastEditTime: 2021-11-18 09:49:59
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \li-yuwei\demo-work\src\utils\reqeust.js
 */
import axios from "axios";
import cookie from "js-cookie";
import NProgress from "nprogress";
import "nprogress/nprogress.css";
const request = axios.create({
    timeout: 10000,
});
request.interceptors.request.use(
    (config) => {
        NProgress.start();
        const token = cookie.get("token");
        config.headers.authorization = token;
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);
request.interceptors.response.use(
    (response) => {
        const res = response.data;
        NProgress.done();
        if (res.code !== 200) return alert("错误!!!");
        return res;
    },
    (error) => {
        return Promise.reject(error);
    }
);
export default request;